<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Pay;

/**
 * 示例接口
 */
class Demo extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['test', 'test1','test4','test5','test6','scan'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['test2','test4','test5','test6','scan'];

    /**
     * 测试方法
     *
     * @ApiTitle    (测试名称)
     * @ApiSummary  (测试描述信息)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/demo/test/id/{id}/name/{name})
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="integer", required=true, description="会员ID")
     * @ApiParams   (name="name", type="string", required=true, description="用户名")
     * @ApiParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    public function test()
    {
        $this->success('返回成功', $this->request->param());
    }

    /**
     * 无需登录的接口
     *
     */
    public function test1()
    {
        $this->success('返回成功', ['action' => 'test1']);
    }

    /**
     * 需要登录的接口
     *
     */
    public function test2()
    {
        $this->success('返回成功', ['action' => 'test2']);
    }

    /**
     * 需要登录且需要验证有相应组的权限
     *
     */
    public function test3()
    {
        $this->success('返回成功', ['action' => 'test3']);
    }

    public function test4(){
        $pay = new Pay();
        $data = [
            'seller_member_no' => 6806043394058620928,                         // 卖家标识
            'out_order_no'     => 'no' . date('YmdHi'),                         // 应用平台订单号（唯一的）
            'amount'           => 10,                                          // 订单金额（单位：分）
            'pay_amount'       => 10,                                          // 首次支付金额（单位：分）
            // 'terminal_ip'           => '113.104.180.3',                             // 终端IP
            'terminal_ip'      => $this->request->ip(),                        // 终端IP
            'order_name'       => '测试支付',                                   // 订单名称
            'split_mode'       => 0,                                           // 分账模式
            /* 'front_url'             => '',                                          // 前台通知地址
            'back_url'              => '',                                          // 后台通知地址 */
        ];

        ////// 支付方式
        $data['pay_method'] = ['GATEWAY' => [
            'member_no'     => 6806043394058620928,                         // 卖家标识
            'merchant_no'   => 7194643510113705984,                         // 钱帐通商户号
            'amount'        => 10,                                          // 支付金额，单位：分
        //     'counter_param'         => ['pay_mode' => 'WECHAT'],
          //  'counter_param' => ['pay_mode' => 'ALIPAY'],
            'product_name'  => '测试商品',
            'inte_routing'  => 1,
        ]];

        ///// 分账规则
        $data['split_rule_data'] = ['split_list' => [
            ['member_no' => 6806043394058620928, 'amount' => 10, 'special_account_no' => 'S005'],    // S005分到商户佣金专用账户，仅商户会员
        ]];
       $user =   $pay->consume($data);
       var_dump($data['out_order_no']);
        var_dump($user);
    }
    public function scan(){
        $pay = new Pay();
        $scan = [

                'GATEWAY' => [
//                    'bar_code' =>   'https://pay.wsmsd.cn/r/0000?pageStyle%3DV2%26token%3DCCSSIZ5xm6iemBw0G3U6U40gGMP5rhoKuxVhhVI7XyulHEUboR1J31PIpJVMX1-_icU5Ad-9u14GQ2GZ3Q%3D%3D%26amount%3D10%26payOrderNo%3D24123011012001101011001715427%26mndf%3D1',
//                    'app_id' => '6633965341557002240',
                    'amount' => 10,
//                    'term_base_station'=> '123456',
//                    'term_loc' => '123456',
//                    "hb_fq_seller_percent"=>"",
                    "merchant_no"=>"7194643510113705984",
//                    "amount"=>"1",
//                    "term_base_station"=>"",
//                    "hb_fq_num"=>"",
                    "member_no"=>"6806043394058620928",
                    "product_name" => '测试商品',
//                    "bar_code"=>"6854584110694928384",
//                    "channel_type"=>"",
//                    "app_id"=>"",
//                    "term_loc"=>"",
                ]


        ];
        $data = [
           'pay_amount' => 10,                         //支付金额，
           'order_no'     => '7279688180006514688',                         // 订单号
           'terminal_ip'      => $this->request->ip(),
            'pay_method'    => $scan,
            ];
        echo '<pre>';
        var_dump($data);
        echo '</pre>';
        $user =  $pay->consume_pay($data);
        var_dump($user);
    }
    public function test5(){
        $pay = new Pay();
        $user =  $pay->addUser();
        var_dump($user);
    }
    public function test6(){
        $pay = new Pay();
       // $user =  $pay->findUser();
        $user = $pay-> member_merchant();
        var_dump($user);
    }
}
